package com.ruoyi.teach.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.teach.domain.SchStudentLeave;
import com.ruoyi.teach.service.ISchStudentLeaveService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 学生退学Controller
 * 
 * @author ruoyi
 * @date 2021-12-13
 */
@RestController
@RequestMapping("/teach/leave")
public class SchStudentLeaveController extends BaseController
{
    @Autowired
    private ISchStudentLeaveService schStudentLeaveService;

    /**
     * 查询学生退学列表
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:list')")
    @GetMapping("/list")
    public TableDataInfo list(SchStudentLeave schStudentLeave)
    {
        startPage();
        List<SchStudentLeave> list = schStudentLeaveService.selectSchStudentLeaveList(schStudentLeave);
        return getDataTable(list);
    }

    /**
     * 导出学生退学列表
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:export')")
    @Log(title = "学生退学", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SchStudentLeave schStudentLeave)
    {
        List<SchStudentLeave> list = schStudentLeaveService.selectSchStudentLeaveList(schStudentLeave);
        ExcelUtil<SchStudentLeave> util = new ExcelUtil<SchStudentLeave>(SchStudentLeave.class);
        util.exportExcel(response, list, "学生退学数据");
    }

    /**
     * 获取学生退学详细信息
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:query')")
    @GetMapping(value = "/{lId}")
    public AjaxResult getInfo(@PathVariable("lId") Long lId)
    {
        return AjaxResult.success(schStudentLeaveService.selectSchStudentLeaveByLId(lId));
    }

    /**
     * 新增学生退学
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:add')")
    @Log(title = "学生退学", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SchStudentLeave schStudentLeave)
    {
        return toAjax(schStudentLeaveService.insertSchStudentLeave(schStudentLeave));
    }

    /**
     * 修改学生退学
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:edit')")
    @Log(title = "学生退学", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SchStudentLeave schStudentLeave)
    {
        return toAjax(schStudentLeaveService.updateSchStudentLeave(schStudentLeave));
    }

    /**
     * 删除学生退学
     */
    @PreAuthorize("@ss.hasPermi('teach:leave:remove')")
    @Log(title = "学生退学", businessType = BusinessType.DELETE)
	@DeleteMapping("/{lIds}")
    public AjaxResult remove(@PathVariable Long[] lIds)
    {
        return toAjax(schStudentLeaveService.deleteSchStudentLeaveByLIds(lIds));
    }
    /**
     * 通过学生id查询退学信息
     *
     */
    @RequestMapping("/getLeave")
    public AjaxResult getstuLeave(Long sid){
        return AjaxResult.success(schStudentLeaveService.selectsid(sid));
    }
}
